package com.cmj.Utils;

import com.cmj.dao.UserMapper;
import com.cmj.domain.AppHttpCodeEnum;
import com.cmj.domain.entity.User;
import com.cmj.exception.SystemException;

/**
 * 判断字段是否存在数据中
 */
public class IsExistUtils {

    /**
     * 判断字段是否存在数据库中
     * @param user 注册信息
     * @return true/false
     */
    public static void isOnly(User user,UserMapper userMapper){
        if (userMapper.selExist(user.getUserName(),"user_name") > 0){
            throw new SystemException(AppHttpCodeEnum.USERNAME_EXIST);
        }
        if (userMapper.selExist(user.getNickName(),"nick_name") > 0){
            throw new SystemException(AppHttpCodeEnum.NICKNAME_EXIST);
        }
        if (userMapper.selExist(user.getEmail(),"email") > 0){
            throw new SystemException(AppHttpCodeEnum.EMAIL_EXIST);
        }
        if (userMapper.selExist(user.getPhonenumber(),"phonenumber") > 0){
            throw new SystemException(AppHttpCodeEnum.PHONE_EXIST);
        }
    }
}
